﻿namespace TestTool.Tests.Engine
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using TestTool.Tests.Common.CommonUtils;
    using TestTool.Tests.Definitions.Data;
    using TestTool.Tests.Definitions.Enums;

    internal class ConformanceLogicHandler
    {
        public static List<TestInfo> GetTestsByFeatures(IEnumerable<TestInfo> allTestCases, IEnumerable<Feature> features, bool conformance)
        {
            List<TestInfo> list = new List<TestInfo>();
            IEnumerable<TestInfo> enumerable = null;
            if (conformance)
            {
                enumerable = from TI in allTestCases
                    where TI.RequirementLevel == RequirementLevel.Must
                    select TI;
            }
            else
            {
                enumerable = allTestCases;
            }
            foreach (TestInfo info in enumerable)
            {
                bool flag = true;
                foreach (Feature feature in info.RequiredFeatures)
                {
                    if (!features.ContainsFeature(feature))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    list.Add(info);
                }
            }
            return list;
        }
    }
}

